#include<bits/stdc++.h>
using namespace std;
int n,m;
vector<pair<int,int>> ans;
void solve(){
    ans.clear();
    int b=(n<m);
    if(b) swap(n,m);
    if(n==m){
        for(int i=1;i<=n;i++)
            ans.push_back(make_pair(1,i));
        for(int i=2;i<=n-1;i++)
            ans.push_back(make_pair(n,i));
    }
    else if(m&1){
        for(int i=1;i<=n;i+=m){
            if(i+m>n&&i!=n){
                int l=i-m+m/2+1,r=n-m/2-1;
                for(int j=l;j<=r;j++)
                    ans.push_back(make_pair(j,m/2+1));
                for(int j=1;j<=m;j++)
                    ans.push_back(make_pair(n,j));
            }
            else{
                for(int j=1;j<=m;j++)
                    ans.push_back(make_pair(i,j));
            }
        }
    }
    else{
        for(int i=1;i<=n;i+=m){
            if(i+m>n&&i!=n){
                int l=i-m+m/2+1,r=n-m/2-1;
                for(int j=l;j<=r;j+=2)
                    ans.push_back(make_pair(j,m/2)),ans.push_back(make_pair(j,m/2+1));
                for(int j=1;j<=m;j++)
                    ans.push_back(make_pair(n,j));
            }
            else{
                for(int j=1;j<=m;j++)
                    ans.push_back(make_pair(i,j));
            }
        }
    }
    cout<<ans.size()<<'\n';
    for(int i=0;i<ans.size();i++){
        if(b) swap(ans[i].first,ans[i].second);
        cout<<ans[i].first<<" "<<ans[i].second<<'\n';
    }
    return;
}
int main(){
    freopen("bishop.in","r",stdin);
    freopen("bishop.out","w",stdout);
    std::ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>n>>m;
    solve();
    return 0;
}